package com.mystnihon.tdroid.loader;

import java.io.IOException;
import java.util.ArrayList;

import android.content.Context;
import android.util.Log;
import ca.benow.transmission.TransmissionClient;
import ca.benow.transmission.model.TorrentStatus;

import com.mystnihon.tdroid.config.Config;

public class GetTorrentsLoader extends AbstractAsyncLoader<ArrayList<TorrentStatus>> {
	private static final String TAG = GetTorrentsLoader.class.getSimpleName();
	TransmissionClient mclient;
	int ids[] = null;
	TorrentStatus.TorrentField[] requestedFields = null;

	public GetTorrentsLoader(TransmissionClient client) {
		mclient = client;
	}

	@Override
	protected boolean doLoad(Context context) {
		if (Config.DEBUG_MODE_ENABLED)
			Log.d(TAG, "Loading");
		try {
			setDataObject(mclient.getTorrents(ids, requestedFields));
			if (Config.DEBUG_MODE_ENABLED)
				Log.d(TAG, "Loading return true");
			return true;
		} catch (IOException e) {
			if (Config.ERROR_MODE_ENABLED)
				Log.e(TAG, "Erreur", e);
		}
		if (Config.DEBUG_MODE_ENABLED)
			Log.d(TAG, "Loading return false");
		return false;
	}

}
